Skip to content

Add MSBuild csproj recipes + .sln .njsproj filter#7518

Open
macsux wants to merge 4 commits intomainfrom
macsux/csproj-recipes
Open

Add MSBuild csproj recipes + .sln .njsproj filter#7518
macsux wants to merge 4 commits intomainfrom
macsux/csproj-recipes

Conversation

@macsux
Copy link
Copy Markdown
Contributor

@macsux macsux commented Apr 29, 2026

Summary

  • Adds three csproj recipes registered via CsprojRecipeActivator: AddFrameworkReference (e.g., for Microsoft.AspNetCore.App after dropping the .All meta-package), RemoveDotNetCliToolReference (gone in net3+), and RemoveMSBuildProperty (e.g., RuntimeFrameworkVersion, PackageTargetFallback).
  • Adds a Java recipe org.openrewrite.csharp.sln.RemoveNjsprojFromSolution that strips .njsproj Project entries and their ProjectConfigurationPlatforms / NestedProjects entries from .sln/.slnx (since the .NET SDK doesn't ship Microsoft.NodejsTools.targets).
  • Updates RewriteTest so test specs with a SourcePath for .cs files route through the local CSharpParser instead of the Java RPC parser, enabling tests that need C# files at specific paths.

Test plan

  • ./gradlew :rewrite-csharp:test
  • dotnet test for the rewrite-csharp C# solution (AddFrameworkReferenceTests, RemoveDotNetCliToolReferenceTests, RemoveMSBuildPropertyTests)

macsux added 2 commits April 28, 2026 17:58
C# (csproj transformations, registered with CsprojRecipeActivator):
- AddFrameworkReference: adds <FrameworkReference> when removing meta-packages
  (e.g., Microsoft.AspNetCore.App after dropping Microsoft.AspNetCore.All)
- RemoveDotNetCliToolReference: removes <DotNetCliToolReference> items
  (the netcoreapp2.x per-project CLI tool mechanism, gone in net3+)
- RemoveMSBuildProperty: removes named <PropertyGroup> properties
  (e.g., RuntimeFrameworkVersion, PackageTargetFallback)

Java (sln cleanup):
- org.openrewrite.csharp.sln.RemoveNjsprojFromSolution: removes Project
  entries with .njsproj (Node.js Tools) extension from .sln/.slnx, plus
  associated ProjectConfigurationPlatforms / NestedProjects entries.
  dotnet build can't process .njsproj because the SDK doesn't ship
  Microsoft.NodejsTools.targets.

Note: the Java sln recipe is in the rewrite-csharp jar but mod CLI's
marketplace currently doesn't expose Java recipes from rewrite-csharp via
the NuGet recipe bundle path — the recipe is registered in recipes.csv
and discoverable on classpath but not yet usable from a NuGet recipe
package. Foundation is in place for follow-up.
…h set

Previously, any test SourceSpec with a non-null SourcePath was routed through
the Java RPC parser, which doesn't ship a C# parser — so multi-project tests
that needed C# files at specific paths (e.g., to test path-based per-project
recipe scoping) couldn't be expressed.

Now: .cs source paths route through the local CSharpParser with the test's
sourcePath; only non-.cs/non-.csproj source paths go to Java RPC. Local C#
parsing already supports a custom sourcePath via CSharpParser.Parse(...,
sourcePath: ...) — this just plumbs the test's spec.SourcePath through.

Enables tests like AddNuGetPackageReferenceIfTypeUsedTest where the recipe
needs to map .cs files to their containing csproj by directory prefix.
macsux added 2 commits April 29, 2026 11:11
The recipe was registered in the C# environment but is not yet usable
from a NuGet recipe package, and the corresponding recipes.csv entry
was reverted — leaving recipeCsvValidateCompleteness to fail in CI.
Drop the recipe for now; it can be reintroduced when the marketplace
path for Java recipes in rewrite-csharp is in place.
Previously RPC_TEST_SERVER_CLASSPATH was required, and a stale value
inherited from a different rewrite checkout would silently point tests
at outdated Java JARs — surfacing as cryptic "recipe didn't fire"
failures. Now resolve the classpath file from the loaded SDK assembly
location (handling both in-repo runs and consuming projects that source-
link via `external/openrewrite/rewrite`), and prefer the SDK-relative
file when the env var is older or missing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

1 participant